<template>
  <el-container class="container">
    <!-- 头部 -->
    <el-header>
      <div>
        <img src="../assets/heima.png" alt="" />
        <span>电商管理系统</span>
      </div>
      <el-button type="info" @click="loginout">退出</el-button>
    </el-header>
    <!-- 下部 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isfalg ? '64px' : '200px'">
        <div @click="hande">|||</div>
        <el-menu
          background-color="#333744"
          :default-active="'/'+isactive"
          text-color="#fff"
          :collapse-transition="false"
          active-text-color="#409EFF"
          unique-opened
          :collapse="isfalg"
          router
        >
          <el-submenu :index="item.id + ''" v-for="item in list" :key="item.id">
            <!-- 第一级导航 -->
            <template slot="title">
              <!-- 第一季图标 -->
              <i :class="icoe[item.id]" style="margin-right: 10px"></i>
              <!-- 第一季文本 -->
              <span>{{ item.authName }}</span>
            </template>
            <!-- 二级导航 -->

            <el-menu-item
              :index="'/' + list.path"
              icon="el-icon-menu"
              v-for="list in item.children"
              :key="list.id"
              @click="active(list.path)"
            >
              <i class="el-icon-menu"></i>
              {{ list.authName }}</el-menu-item
            >
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主体 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>




<script>
export default {
  data() {
    return {
      list: [],
      icoe: {
        125: "iconfont icon-user",
        103: "iconfont icon-tijikongjian",
        101: "iconfont icon-shangpin",
        102: "iconfont icon-danju",
        145: "iconfont icon-baobiao",
      },
      isfalg: false,
      isactive: "",
    };
  },
  created() {
    this.menu();
    
    this.isactive=window.sessionStorage.getItem('istoanke')
  },
  methods: {
    loginout() {
      window.sessionStorage.clear("toank");
      this.$router.push("/login");
    },
    async menu() {
      const { data: res } = await this.$http.get("menus");
      // console.log(res);
      if (res.meta.status !== 200) return this.$message.error("数据获取失败");
      this.list = res.data;
    },
    hande() {
      this.isfalg = !this.isfalg;
    },
    active(isactives) {
      console.log(isactives,'...lll.');
      // 每次刷新时加载高亮
      window.sessionStorage.setItem('istoanke',isactives)
      this.isactive = isactives;
    },
  },
};
</script>




<style lang="less" scoped>
.container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 10px;
  align-items: center;
  color: #fff;
  font-size: 20px;
  div {
    display: flex;
    align-items: center;
    span {
      margin-left: 20px;
    }
  }
}
.el-aside {
  background-color: #333744;
  div {
    color: #fff;
    text-align: center;
    font-size: 15px;
    cursor: pointer;
  }
}
.main {
  background-color: #eaedf1;
}
.el-submenu {
  margin-right: 0;
}
</style>